<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title>修改商品</title>
    <style type="text/css">
        .checkbox{
             margin-left:5px;
             width:90px;
             margin-top: 10px;
        }
        textarea{
            width: 300px;
            height: 100px;
        }
           .hd-title-header{text-align:left;font-weight:bold;font-size:14px;}
        #uploadList  li{float:left;list-style:none;}
         #uploadList1  li{float:left;list-style:none;}
         .w200{width: 200px;}
    </style>
    <link rel="stylesheet" type="text/css" href="http://localhost/yhd/Static/hdjs/hdjs.css"/>
    <script type="text/javascript" charset="utf-8" src="http://localhost/yhd/Static/ueditor1_4_3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="http://localhost/yhd/Static/ueditor1_4_3/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="http://localhost/yhd/Static/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
     <!--载入uploadify相关文件-->
    <script type="text/javascript" src="http://localhost/yhd/Static/uploadify/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="http://localhost/yhd/Static/uploadify/jquery.uploadify.min.js"></script>
    <link href="http://localhost/yhd/Static/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
   <!-- 异步删除 -->
    <script type="text/javascript">
        //点击x删除图片
        $('.del-img').live('click',function(){
            var liObj = $(this).parents('li');
            //找到父级li里面的地址
            var path = liObj.attr('path');
            //发异步到服务器删除
            $.ajax({
                type:"post",
                url:"<?php echo U('delImg');?>",
                data:{path:path},
                success:function(data){
                    //移除图片
                    liObj.remove();
                }
            });
        })
    </script>


    <!-- 异步调取规格和属性 -->

    <!-- 克隆 -->
    <script type="text/javascript">
          $(function(){
                //点击增加
                $('.add').live('click',function(){
                    
                    //克隆一个tr
                    var tr = $(this).parents('tr').clone();
                    $('#spec').append(tr);
                    
                })
                
                //live给未来元素绑定事件
                $('.remove').live('click',function(){
                    if($('tr').length > 2){
                        $(this).parents('tr').remove();
                    }
                    
                })
            })
            
        </script>
  <script type="text/javascript">
$(function(){
 $('select[name=cat_id]').change(function(){
   // 获得选中的option中的type_id
     var type_id=$(':selected').attr('type_id');
     if (type_id==0) {
                    alert('顶级分类不能添加商品');
                    return;
                };
     $('input[name=type_id]').val(type_id);
    $.ajax({
    type:"post",
   url:"<?php echo U('Goods/getAttrSpec');?>",
    data:{type_id:type_id},
    dataType:'json',
        success:function(phpData){
                        //属性
                        var attr = '';
                        //规格
                        var spec = '';
                        $.each(phpData, function(k,v) {    
                            //如果是属性(不可选)    
                            if(v.class == 0){
                                attr += '<tr><td>'+v.attr_name+'</td><td><select class="w200" name="attr[]"><option value="0">请选择</option>';
                                $.each(v.attr_value, function(kk,vv) {    
                                    attr += '<option value="'+vv+'">' + vv + '</option>';                                                          
                                });
                                attr += '</select></td><td><input type="hidden" name="Ataid[]" value="'+v.attr_id+'"/></td></tr>';
                            }else{
                                spec += '<tr><td>'+v.attr_name+'</td><td><select class="w200" name="spec[]"><option>请选择</option>';
                                $.each(v.attr_value, function(kk,vv) {    
                                    spec += '<option>' + vv + '</option>';                                                          
                                });
                                spec += '</select></td><td><span>附加价格</span><input type="text" name="attr_price[]"/><input type="hidden" name="taid[]" value="'+v.attr_id+'"/></td><td><a class="add hd-btn hd-btn-success" href="javascript:;">添加规格</a><a class="remove hd-btn hd-btn-success" href="javascript:;">删除规格</a></td></tr>';
                            }
                        });
                       
                        $('#attr').html(attr);
                        $('#spec').html(spec);
                        
                    }



    });
 
 });


})

  </script>

<script type="text/javascript">
        $(function(){

            $('.close-img').click(function(){
                //清空图片和关闭按钮 显示input file表单
                $('.thumb-td').html(' <input type="file" name="goods_img" id="" /> ');
                
            })
        })
    </script>

</head>
<body>
    

<div class="wrap">
    <div class="hd-title-header">修改商品</div>
    <form action="" method="post" class="form-inline hd-form" enctype="multipart/form-data">
        <table class="hd-table hd-table-list">
            <tr>
                <th class="w100">商品名称</th>
                <td class="w100">
                    <input type="text" name="goods_name" class="w200" value="<?php echo $olddata['goods_name'];?>"/> 
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">商品货号</th>
                <td class="w100">
                    <input type="text" name="goods_sn" class="w200" value="<?php echo $olddata['goods_sn'];?>" /> 
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">商品分类</th>
                <td>
                    <select name="cat_id" class="w200">
                        <option value="0">请选择分类</option>
                        <?php foreach ($cateData as $k=>$v){?>
                        <option value="<?php echo $v['cid'];?>" type_id="<?php echo $v['type_id'];?>"     <?php if($olddata['cat_id']==$v['cid']){ ?>selected<?php } ?>><?php echo $v['_name'];?></option>
                       
                        <?php }?>
                    </select>
                </td>
                <td></td>
            </tr>
           
           

            <!-- 获取商品品牌 -->
            <tr>
                <th class="w100">商品品牌</th>
                <td>
                    <select name="brand_id" class="w200">
                     <option value="0">请选择商品品牌</option>
                    <?php foreach ($brand as $k=>$v){?>
            
                        <option value="<?php echo $v['brand_id'];?>"     <?php if($olddata['brand_id']==$v['brand_id']){ ?>selected<?php } ?> ><?php echo $v['brand_name'];?></option>

                     <?php }?> 
                    </select>
                </td>
               
            </tr>

            <tr>
                <th class="w100">本店价</th>
                <td class="w100">
                    <input type="text" name="shop_price" class="w200" value="<?php echo $olddata['shop_price'];?>"/> 
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">市场价</th>
                <td class="w100">
                    <input type="text" name="market_price" class="w200" value="<?php echo $olddata['market_price'];?>"/> 
                </td>
                <td></td>
            </tr>
             <tr>
                <th class="w100">促销价</th>
                <td class="w100">
                    <input type="text" name="promote_price" class="w200" value="<?php echo $olddata['promote_price'];?>"/> 
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">库存</th>
                <td class="w100">
                    <input type="text" name="goods_number" class="w200" value="<?php echo $olddata['goods_number'];?>"/> 
                </td>
                <td></td>
            </tr>
             <tr>
                <th class="w100">点击量</th>
                <td class="w100">
                    <input type="text" name="click" class="w200" value="<?php echo $olddata['click'];?>"/> 
                </td>
                <td></td>
            </tr>
           
             <!-- 商品图片 -->
          <tr>
                   <div lab="uploadFile">
              <th class="w100"> 商品图片：</th> <td class="w100"> <input id="file1" type="file" multiple="true" class="w200">  </td>
              <!--   <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span> -->
                <script type="text/javascript">
                    $(function() {
                        $('#file1').uploadify({
                            'formData'     : {//POST数据
                                '<?php echo session_name();?>' : '<?php echo session_id();?>',
                            },
                            'fileTypeDesc' : '上传文件',//上传描述
                            'fileTypeExts' : '*.jpg;*.png',
                            'swf'      : 'http://localhost/yhd/Static/uploadify/uploadify.swf',
                            'uploader' : '<?php echo U("upload");?>',
                            'buttonText':'选择文件',
                            'fileSizeLimit' : '2000KB',
                            'uploadLimit' : 1000,//上传文件数
                            'width':65,
                            'height':25,
                            'successTimeout':10,//等待服务器响应时间
                            'removeTimeout' : 0.2,//成功显示时间
                            'onUploadSuccess' : function(file, data, response) {
                                data=$.parseJSON(data);
                                var imageUrl = data.image?data.url:'http://localhost/yhd/Static/image/default.png';
                                var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' style='width:100px;heigth:100px;'/><a href='javascript:;' style='color:red' class='del-img'>X</a>";
                                //把地址放到隐藏域，这样可以提交到服务器了
                                li += '<input type="hidden" name="goods_img" value="'+data.path+'"/>';
                                li += '</li>';
                                $("#uploadList1 ul").prepend(li);
                            }
                        });
                    });
                </script>
                <td>
                <div id="uploadList1">
                    <ul>
                      <li><img src='http://localhost/yhd/<?php echo $olddata['goods_img'];?>' style='width:100px;heigth:100px;'/><a href='javascript:;' style='color:red' class='del-img'>X</a>
                      <input type="hidden" name="goods_img" value="<?php echo $olddata['goods_img'];?>"/></li>
                    </ul>
                </div>
                </td>
            </div>
            </tr>
                      <!-- 商品图集 -->
            <tr>
                   <div lab="uploadFile">
              <th class="w100"> 商品图集：</th> <td class="w100"> <input id="file" type="file" multiple="true" class="w200">  </td>
              <!--   <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span> -->
                <script type="text/javascript">
                    $(function() {
                        $('#file').uploadify({
                            'formData'     : {//POST数据
                                '<?php echo session_name();?>' : '<?php echo session_id();?>',
                            },
                            'fileTypeDesc' : '上传文件',//上传描述
                            'fileTypeExts' : '*.jpg;*.png',
                            'swf'      : 'http://localhost/yhd/Static/uploadify/uploadify.swf',
                            'uploader' : '<?php echo U("upload");?>',
                            'buttonText':'选择文件',
                            'fileSizeLimit' : '2000KB',
                            'uploadLimit' : 1000,//上传文件数
                            'width':65,
                            'height':25,
                            'successTimeout':10,//等待服务器响应时间
                            'removeTimeout' : 0.2,//成功显示时间
                            'onUploadSuccess' : function(file, data, response) {
                                data=$.parseJSON(data);
                                var imageUrl = data.image?data.url:'http://localhost/yhd/Static/image/default.png';
                                var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' style='width:100px;heigth:100px;'/><a href='javascript:;' style='color:red' class='del-img'>X</a>";
                                //把地址放到隐藏域，这样可以提交到服务器了
                                li += '<input type="hidden" name="photo[]" value="'+data.path+'"/>';
                                li += '</li>';
                                $("#uploadList ul").prepend(li);
                            }
                        });
                    });
                </script>
                <td>
                <div id="uploadList">
                    <ul>
                       <?php foreach ($big as $k=>$v){?> 
                           <li path='"+data.path+"' url='"+data.url+"'><img src='http://localhost/yhd/<?php echo $v;?>' style='width:100px;heigth:100px;'/><a href='javascript:;' style='color:red' class='del-img'>X</a>
                            <input type="hidden" name="photo[]" value="<?php echo $v;?>"/></li>
                       <?php }?>
                    </ul>
                </div>
                </td>
            </div>
            </tr>
            <tr>
                <th class="w100">加入推荐</th>
                <td>
                    <label class="checkbox-inline">
                        精品
                        <input type="checkbox" value="1" name="is_best" class="check_input"
                            <?php if($olddata['is_best']){ ?>checked<?php } ?>   
                        />
                    </label>
                    <label class="checkbox-inline">
                        新品
                        <input type="checkbox" value="1" name="is_new" class="check_input"
                                 <?php if($olddata['is_new']){ ?>checked<?php } ?> 

                        />
                    </label>
                    <label class="checkbox-inline">
                        热销
                        <input type="checkbox" value="1" name="is_hot" class="check_input"
                                 <?php if($olddata['is_hot']){ ?>checked<?php } ?> 
                        />
                    </label>
                    
                </td>
                <td></td>
            </tr>
           
           
             <tr>
                <th class="w100">商品描述</th>
                <td>
                    <textarea name="goods_brief" id="" cols="30" rows="10"><?php echo $olddata['goods_brief'];?></textarea>
                </td>
                <td></td>
            </tr>
             <tr>
                <th class="w100">商品详情</th>
                <td>
                 <script id="ed" type="text/plain" style="width:800px;height:400px;" name="intro"><?php echo $detailData['intro'];?></script>
                    <script>
                        var ue = UE.getEditor('ed');
                    </script>  
                </td>
                <td></td>
            </tr>
         <tr>
                  
            <table class="hd-table hd-table-form" id='attr'>
            <p class="hd-title-header">商品属性</p>
                     <tbody>
                     <?php foreach ($attrdata as $k=>$v){?>
                      <tr>
                        <td><?php echo $v['attr_name'];?></td>
                        <td>
                        <select class="w200" name="attr[]">
                          <option value="0">请选择</option>
                         <?php foreach ($v['attr_value'] as $key=>$value){?>
                        
                          <option     <?php if(in_array($value,$attr_value) == true){ ?>selected<?php } ?>><?php echo $value;?></option>
                      
                          <?php }?>
                          </select>

                          </td>
                        <td><input name="Ataid[]"  type="hidden" value="<?php echo $v['attr_id'];?>"></td>
                      </tr>
                       <?php }?>
                    </tbody>

            </table>
            </tr>
            <tr>
          
            <table class="hd-table hd-table-form" id='spec'>
              <p class="hd-title-header">商品规格</p>
                <tbody>
                  <?php foreach ($specdata as $k=>$v){?>
                <tr>
                  <td><?php echo $v['attr_name'];?></td>
                  <td><select class="w200" name="spec[]">
                    <option>请选择</option>
                    <?php foreach ($v['attr_value'] as $key=>$value){?>
                        <option     <?php if(in_array($value,$attr_value) == true){ ?>selected<?php } ?>><?php echo $value;?></option>     
                    <?php }?>
                    </select>
                </td>
                <td><span>附加价格</span>
                  <?php foreach ($v['attr_value'] as $key=>$value){?>
                            <?php if(in_array($value,$attr_value) == true){ ?>
                            <foreach from="$GoodsAttr" key="$ke" value="$va">
                                    <?php if($value==$va['attr_value']){ ?>
                                    <input type="text" name="attr_price[]" value="<?php echo $va['attr_price'];?>"/>
                                <?php } ?>
                            <?php }?>
                        <?php } ?>
                    <?php }?>
                <input name="taid[]" value="15" type="hidden" value="<?php echo $v['attr_id'];?>"></td><td>
              <!--   <a class="add hd-btn hd-btn-success" href="javascript:;">添加规格</a>
                <a class="remove hd-btn hd-btn-success" href="javascript:;">删除规格</a> -->
                </td>
                </tr>
                </tbody>
            </table>
            </tr>
        </table>
        <div class="position-bottom">
        <input type="hidden" name="goods_id" value="<?php echo $hd['get']['goods_id'];?>" />
            <input type="submit" class="hd-btn hd-btn-success" value="修改"/>
        </div>
    </form>
</div>
</body>
</html>